//
//  ZQAccountTool.m
//  柳州微博
//
//  Created by Apple_Lzzy40 on 16/10/10.
//  Copyright © 2016年 Apple_Lzzy40. All rights reserved.
//

#import "ZQAccountTool.h"
#import "ZQAccount.h"
#define LWAccountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"account.archive"]
@implementation ZQAccountTool
/**
 *  保存帐号信息
 *
 *  @param account 账号模型或账号实例
 */

+(void)saveAccount:(ZQAccount *)account
{
  [NSKeyedArchiver archiveRootObject:account toFile:LWAccountPath];
}
/**
 *  返回账号模型
 *
 *  @return 账号模型
 */
+(ZQAccount *)account
{
//    NSLog(@"%@", LWAccountPath);
  //获取帐号信息
    ZQAccount  *  account=[NSKeyedUnarchiver unarchiveObjectWithFile:LWAccountPath];
    // 获取过期的秒数
  long long expires_in= [account.expires_in longLongValue];
    //合成过期的时间
    NSDate * expiresTime=[account.create_time dateByAddingTimeInterval:expires_in];
    
    //获取当前时间
    NSDate * now=[NSDate date];
    NSComparisonResult reslut=[expiresTime compare:now];
//    NSLog(@"expiresTime=%@",expiresTime);
//    NSLog(@"now=%@",now);
//    NSLog(@"%ld",reslut);
    if (reslut ==NSOrderedAscending || reslut ==NSOrderedSame) {
        
        return nil;
    }
    return  account;
}

@end
